package com.iweb.tmall.mybatis;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@MapperScan("com.iweb.tmall.mapper")
public class MybatisConfig {
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        /* 创建一个分页拦截器对象, 参数是枚举类型DbType, 表示使用哪一种数据库 */
        PaginationInnerInterceptor pii = new PaginationInnerInterceptor(DbType.MYSQL);
        /* 创建一个MybatisPlus拦截器对象 (拦截器注册表对象) */
        MybatisPlusInterceptor mpi = new MybatisPlusInterceptor();
        /* 将分页拦截器注册到MybatisPlus拦截器中 */
        mpi.addInnerInterceptor(pii);
        /* 返回MybatisPlus拦截器对象 */
        return mpi;
    }
}
